package cn.org.timespace.easyframe.util.tag;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 控制点
 * 
 * @author 
 * 
 */
public class ControlPointTag extends BodyTagSupport {

	private static final Log log = LogFactory.getLog(ControlPointTag.class);

	private static final long serialVersionUID = 3984693398166947061L;

	public ControlPointTag() {
		super();
	}

	// 控制点编码 必须的
	private String controlPointCode;

	public int doStartTag() {
		
		if (controlPointCode == null || controlPointCode.equals("")) {
			return SKIP_BODY;
		}
		
		HttpSession session = pageContext.getSession();
		Map cpMap = (Map) session.getAttribute("cpMap");
		if(cpMap != null)
		{
			if(cpMap.containsKey(controlPointCode)){
				return EVAL_BODY_BUFFERED;
			}
		}

		return SKIP_BODY;
	}

	public int doEndTag() throws JspTagException {
		try {
			if (bodyContent != null) {
				bodyContent.writeOut(pageContext.getOut());
				bodyContent = null;
				controlPointCode = null;
			}
		} catch (IOException e) {
			throw new JspTagException(e.toString());
		}
		return EVAL_PAGE;
	}

	public String getControlPointCode() {
		return controlPointCode;
	}

	public void setControlPointCode(String controlPointCode) {
		this.controlPointCode = controlPointCode;
	}

	public void release() {
		super.release();
	}
}
